import { defineStore } from 'pinia'
import { ref } from 'vue'


function initState(){
  return {
    isCollapse: false,//控制侧边栏是否折叠
    tags:[
      {
          path: '/home',
          name: 'home',
          label: '首页',
          icon:'house',
          index: 11,
      },
    ],//标签页
    currentMenu: null ,  //当前选中的菜单
    menuList: [
      {
        path: '/recycle',
        name: 'recycle',
        label: '回收站',
        icon: 'ShoppingCart',
        index: 9,
      },
      {
          path: '/chat',
          name: 'chat',
          icon: 'ChatDotSquare',
          label: '聊天',
          index: 2,//这里弄成2，是为了根据索引值获取全部文件的信息
      },
      {
        path: '/user',
        name: 'user',
        icon: 'User',
        label: '个人中心',
        index:10,
      },
      
      {
          path: '/mine',
          name: 'mine',
          label: '我的文件',
          icon: 'folder',
          children: [
              {
                  path: '/allFiles',
                  name: 'allFiles',
                  label: '全部文件',
                  icon: 'folder',
                  index: 2,
              },
              {
                  path: '/folder',
                  name: 'folder',
                  label: '文件夹',
                  icon: 'folder',
                  index: 3,
              },
              {
                  path: '/image',
                  name: 'image',
                  label: '图片',
                  icon: 'Picture',
                  index: 4,
              },
              {
                  path: '/video',
                  name: 'video',
                  label: '视频',
                  icon: 'VideoPlay',
                  index: 5,
              },
              {
                  path: '/document',
                  name: 'document',
                  label: '文档',
                  icon: 'document',
                  index: 6,
              },
              {
                  path: '/audio',
                  name: 'audio',
                  label: '音频',
                  icon: 'Mic',
                  index: 7,
              },
              {
                  path: 'other',
                  name: 'other',
                  label: '其他',
                  icon: 'More',
                  index: 8,
              },
          ]
      },
    ], //菜单列表
    token:''
  }
}

export const useAllDataStore = defineStore('allData', (a) => {
    const state=ref(initState())
    
    //添加标签页
    function selectMenu(val){
      if(val.name === 'home'){
        state.value.currentMenu = null
      }else{
        let index = state.value.tags.findIndex(item => item.name === val.name)
        index===-1?state.value.tags.push(val):"";
      }
    }

    //删除标签页
    function updateTags(val){
      let index = state.value.tags.findIndex(item => item.name === val.name)
      state.value.tags.splice(index,1)
    }

    function updateMenuList(val){
      state.value.menuList = val
    }

    //更新当前选中的菜单（顶部菜单栏）
    function updateCurrentMenu(val){
      state.value.currentMenu = val
    }
    
    return {
      state,
      selectMenu,
      updateTags,
      updateMenuList,
      updateCurrentMenu
    }
})